import { Button, TextArea } from '@douyinfe/semi-ui'
import { useState } from 'react'

export default function AliPayText() {
  const [value, setValue] = useState<string>()

  return (
    <div>
      <TextArea
        autosize
        value={value}
        onChange={(value) => setValue(value)}
      ></TextArea>

      <Button
        onClick={() => {
          submit(value!)
        }}
        className="m-t-10 m-l-10"
      >
        提交
      </Button>
    </div>
  )
}

// 点击提交按钮时
function submit(value: string) {
  const divForm = document.getElementsByTagName('divform')
  if (divForm.length) {
    document.body.removeChild(divForm[0])
  }
  const div = document.createElement('divform')
  div.innerHTML = value
  document.body.appendChild(div)
  document.forms[0].setAttribute('target', '_blank')
  document.forms[0].submit()
}
